主题
获取绑定摄像头信息 - GetBindCameraInfo
函数简介
读取当前实例已用 display="camera" 绑定的摄像头协商结果。actual.width / actual.height 为当前截图像素大小。
未绑定摄像头时返回 0,不返回 JSON。
绑定方式见 BindWindowEx 的 camera 说明。像素大小也可以用 GetClientSize(hwnd 传 0)读取。
接口名称
GetBindCameraInfoDLL调用
c
int64_t GetBindCameraInfo(int64_t instance);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
返回 JSON
| 字段 | 类型 | 说明 |
|---|---|---|
| ok | 布尔 | 摄像头是否已成功打开并完成格式协商。 |
| device | 字符串 | 打开时使用的设备标识(索引或设备名)。 |
| deviceIndex | 整数 | 设备索引。按名称打开时可能为 -1。 |
| deviceName | 字符串 | 设备友好名。按索引打开时可能为空。 |
| backend | 字符串 | 采集后端,如 MSMF、DSHOW、DEFAULT。 |
| error | 字符串 | 失败原因。ok 为 true 时为空。 |
| requested | 对象 | 请求格式:width、height、fps、fourcc。0 或空字符串表示绑定时未指定。 |
| actual | 对象 | 协商后的实际格式。width / height 为当前帧像素大小;channels 当前为 4;pixelFormat 当前为 BGRA。设备未报告帧率时 fps 可能为 0。 |
json
{
"ok": true,
"device": "0",
"deviceIndex": 0,
"deviceName": "",
"backend": "MSMF",
"error": "",
"requested": { "width": 1280, "height": 720, "fps": 30.0, "fourcc": "MJPG" },
"actual": {
"width": 1280,
"height": 720,
"fps": 30.0,
"fourcc": "MJPG",
"channels": 4,
"pixelFormat": "BGRA"
}
}示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
ola.SetConfig("{\"CameraIndex\":0,\"CameraWidth\":1920,\"CameraHeight\":1080,\"CameraFps\":30.0,\"CameraFourcc\":\"MJPG\"}");
ola.BindWindowEx(0, "camera", "normal", "normal", "", 0);
std::string info = ola.GetBindCameraInfo();csharp
using OLAPlug;
var ola = new OLAPlugServer();
ola.SetConfig("{\"CameraIndex\":0,\"CameraWidth\":1920,\"CameraHeight\":1080,\"CameraFps\":30.0,\"CameraFourcc\":\"MJPG\"}");
ola.BindWindowEx(0, "camera", "normal", "normal", "", 0);
string info = ola.GetBindCameraInfo();python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ola.SetConfig('{"CameraIndex":0,"CameraWidth":1920,"CameraHeight":1080,"CameraFps":30.0,"CameraFourcc":"MJPG"}')
ola.BindWindowEx(0, "camera", "normal", "normal", "", 0)
info = ola.GetBindCameraInfo()java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
ola.SetConfig("{\"CameraIndex\":0,\"CameraWidth\":1920,\"CameraHeight\":1080,\"CameraFps\":30.0,\"CameraFourcc\":\"MJPG\"}");
ola.BindWindowEx(0, "camera", "normal", "normal", "", 0);
String info = ola.GetBindCameraInfo();go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ola.SetConfig("{\"CameraIndex\":0,\"CameraWidth\":1920,\"CameraHeight\":1080,\"CameraFps\":30.0,\"CameraFourcc\":\"MJPG\"}")
ola.BindWindowEx(0, "camera", "normal", "normal", "", 0)
info := ola.GetBindCameraInfo()rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
ola.set_config("{\"CameraIndex\":0,\"CameraWidth\":1920,\"CameraHeight\":1080,\"CameraFps\":30.0,\"CameraFourcc\":\"MJPG\"}");
ola.bind_window_ex(0, "camera", "normal", "normal", "", 0);
let info = ola.get_bind_camera_info();cpp
var ola = com("OlaPlug.OlaSoft")
ola.SetConfig("{\"CameraIndex\":0,\"CameraWidth\":1920,\"CameraHeight\":1080,\"CameraFps\":30.0,\"CameraFourcc\":\"MJPG\"}")
ola.BindWindowEx(0, "camera", "normal", "normal", "", 0)
var info = ola.GetBindCameraInfo()vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.SetConfig("{""CameraIndex"":0,""CameraWidth"":1920,""CameraHeight"":1080,""CameraFps"":30.0,""CameraFourcc"":""MJPG""}")
ola.BindWindowEx 0, "camera", "normal", "normal", "", 0
info = ola.GetBindCameraInfo()text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.SetConfig (“{\“CameraIndex\“:0,\“CameraWidth\“:1920,\“CameraHeight\“:1080,\“CameraFps\“:30.0,\“CameraFourcc\“:\“MJPG\“}”)
ola.BindWindowEx (0, “camera”, “normal”, “normal”, “”, 0)
info = ola.GetBindCameraInfo()aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.SetConfig('{"CameraIndex":0,"CameraWidth":1920,"CameraHeight":1080,"CameraFps":30.0,"CameraFourcc":"MJPG"}');
ola.BindWindowEx(0, "camera", "normal", "normal", "", 0);
var info = ola.GetBindCameraInfo();text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.SetConfig ("{\"CameraIndex\":0,\"CameraWidth\":1920,\"CameraHeight\":1080,\"CameraFps\":30.0,\"CameraFourcc\":\"MJPG\"}")
ola.BindWindowEx (0, "camera", "normal", "normal", "", 0)
文本型 info = ola.GetBindCameraInfo()cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
ola.SetConfig("{\"CameraIndex\":0,\"CameraWidth\":1920,\"CameraHeight\":1080,\"CameraFps\":30.0,\"CameraFourcc\":\"MJPG\"}");
ola.BindWindowEx(0, "camera", "normal", "normal", "", 0);
std::string info = ola.GetBindCameraInfo();原生 DLL 调用
cpp
int64_t ptr = GetBindCameraInfo(instance);
// 读取 JSON 后调用 FreeStringPtr(ptr)csharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long GetBindCameraInfo(long ola);
long ptr = GetBindCameraInfo(instance);python
from ctypes import CDLL, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.GetBindCameraInfo.restype = c_int64
ptr = ola.GetBindCameraInfo(instance)返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 字符串指针,内容为绑定摄像头信息 JSON。未绑定摄像头或失败返回 0。返回的字符串指针需要调用 FreeStringPtr 释放内存。 |
注意事项
| 项目 | 说明 |
|---|---|
| 只描述绑定会话 | 本接口读取的是 display="camera" 绑定结果,与 OpenCamera 系列返回的视频句柄无关。视频句柄用 GetVideoInfo。 |
| 截图坐标 | 绑定成功后,Capture / FindPic 的坐标相对摄像头画面左上角。全图可传 0,0,0,0。 |
| 解绑 | UnBindWindow 之后本接口返回 0。 |
